package me.sapling.view;

import me.sapling.model.PageContent;

/**
 * @author sapling
 */
public class OPTPanel extends AbstractPanel {
	public OPTPanel(PageContent[] pages, PageContent[] contents) {
		super(pages, contents);
	}

	@Override
	protected void arithmetic(int i) {
		int count = 0;
		PageContent[] match = new PageContent[pageNumInMemory - 1];
		for (int j = i + 1; j < contents.length; j++) {
			for (int k = 0; k < pageNumInMemory; k++) {
				if (contents[j].getContent() == contentRouter[i][k].getContent()) {
					match[count] = contents[j];
					++count;
					if (count == pageNumInMemory - 1)
						break;
				}
			}
			if (count == pageNumInMemory - 1) break;
		}
		for (int j = 0; j < pageNumInMemory; j++) {
			boolean matched = false;
			for (PageContent aMatch : match) {
				if (aMatch != null && aMatch.getContent() == contentRouter[i][j].getContent()) {
					matched = true;
					break;
				}
			}
			if (!matched) {
				contentOut[i] = contentRouter[i][j];
				contentRouter[i][j] = contents[i];
				break;
			}
		}
	}
}
